import java.util.*;
public class MaxGap {
    public int findMaxGap(int[] A, int n) {
        int max = A[0];
        for (int i = 0; i < A.length; i++) {
            max = Math.max(A[i],max);
        }
        return max - Math.min(A[0],A[n-1]);
    }
}

